﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
//using HA.Data;
using HA.Data.DisplayOptions2;
namespace HA.ModFlow.Controls.Windows.DisplayOptions
{
    /// <summary>
    /// winVectorsOption.xaml 的交互逻辑
    /// </summary>
    public partial class winVectorsOption : Window
    {
        public winVectorsOption(DOVector vector)
        {
            InitializeComponent();
            this._doVector = (DOVector)vector.Clone();
         
        }
        DOVector _doVector = new DOVector();

        public DOVector DoVector
        {
            get { return _doVector; }
            set { _doVector = value; }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.DataContext = this._doVector;
            this .chkVaryLength.IsChecked = this._doVector.IsVaryLength;
            this.chkAutoComRatio.IsChecked = this._doVector.IsAutoCompScaling;
            IsEnbleScaling();
            IsEnableMinMax();
            SolidColorBrush solidColorBrush = new SolidColorBrush(Color.FromArgb(this._doVector.VectorColor.A, this._doVector.VectorColor.R, this._doVector.VectorColor.G, this._doVector.VectorColor.B));
            this.rectVectorsColor.Fill = solidColorBrush;
        }

        private void chkVaryLength_Click(object sender, RoutedEventArgs e)
        {

            IsEnbleScaling();
        }

        private void IsEnbleScaling()
        {
            if (this.chkVaryLength.IsChecked.Value)
            {
                if (this.chkAutoComRatio.IsChecked.Value)
                {
                    this.txtScaling.IsEnabled = false;
                }
                else
                {
                    this.txtScaling.IsEnabled = true ;
                }
                this.chkAutoComRatio.IsEnabled = true ;
            }
            else
            {
                this.chkAutoComRatio.IsEnabled = false;
                this.txtScaling.IsEnabled = false;
            }
        }

        private void IsEnableMinMax()
        {
            //if (this.chkVarColor.IsChecked.Value)
            //{
            //    this.chkColorRange.IsEnabled = true;
            //}
            //else
            //{
            //    this.chkColorRange.IsEnabled = false ;
            //    this.chkColorRange.IsChecked = false;
            //    this.txtMin.IsEnabled = this.chkColorRange.IsChecked.Value;
            //    this.txtMax.IsEnabled = this.chkColorRange.IsChecked.Value;
            //}
        }

        private void chkAutoComRatio_Click(object sender, RoutedEventArgs e)
        {
            IsEnbleScaling();
        }

        private void chkVarColor_Click(object sender, RoutedEventArgs e)
        {
            IsEnableMinMax();
        }

        private void chkColorRange_Click(object sender, RoutedEventArgs e)
        {
            //this.txtMin.IsEnabled = this.chkColorRange.IsChecked.Value;
            //this.txtMax.IsEnabled = this.chkColorRange.IsChecked.Value;
        }

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
          this._doVector.IsVaryLength = this.chkVaryLength.IsChecked .Value ;
           this._doVector.IsAutoCompScaling = this.chkAutoComRatio.IsChecked .Value;
            this.DialogResult = true;
            this.Close();
        }

        private void btnCancal_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void btnVectorsColor_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.ColorDialog dlg = new System.Windows.Forms.ColorDialog();
            dlg.Color = this._doVector.VectorColor;
            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                SolidColorBrush solidColorBrush = new SolidColorBrush(Color.FromArgb(dlg.Color.A, dlg.Color.R, dlg.Color.G, dlg.Color.B));
                this.rectVectorsColor.Fill = solidColorBrush;
                this._doVector.VectorColor = dlg.Color;
            }
        }

        private void chkVaryLength_Click_1(object sender, RoutedEventArgs e)
        {

        }
    }
    public class ConvertToIsEnble : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return !(bool)value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

}
